package ahblue.cn.tanzi.model.home;

import android.content.Context;
import android.widget.Toast;

import java.util.List;

import ahblue.cn.tanzi.data.source.ApiCallback;
import ahblue.cn.tanzi.data.source.RemoteRepository;
import ahblue.cn.tanzi.model.user.CodeModel;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.model.user.UserModel;
import ahblue.cn.tanzi.util.PinkJSON;

/**
 * @author pink-jackstraw
 * @date 2018/11/19
 * @describe  视频列表
 */
public class VideoModel {

    public String id;
    public String title;
    public String file;
    public String image;
    public String user_id;
    public String add_time;
    public String user_name;
    public int comment_count;
    public int early_time;

    public static void getVideoList(final Context context,String type, final VideoListResult mListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getVideoList(type, new ApiCallback<List<VideoModel>>(){
            @Override
            public void onSuccess(List<VideoModel> data) {
                LoginResultModel.saveUserInfo(context, PinkJSON.toJSON(data).toString());
                if (null!=mListener){
                    mListener.conver(data);
                }
            }
            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=mListener){
                    mListener.conver(null);
                }
            }
        });
    }


    public static void collect(final Context context,String operation,String id,String token, final CodeModel.SuccessListener mListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.collect(operation,id,token, new ApiCallback<List<CodeModel>>(){
            @Override
            public void onSuccess(List<CodeModel> data) {
                if (null!=mListener){
                    mListener.conver(true);
                }
            }
            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=mListener){
                    mListener.conver(false);
                }
            }
        });
    }

    public interface VideoListResult {
        void conver(List<VideoModel> model);
    }

}
